/*used ideas from http://www.ibm.com/developerworks/library/x-xformsxbrowser.html*/

var mozWinURL = 'https://addons.mozilla.org/en-US/firefox/downloads/file/25803/mozilla_xforms-0.8.5-fx+mz+sm-win.xpi'
var mozMacURL = 'https://addons.mozilla.org/en-US/firefox/downloads/file/25805/mozilla_xforms-0.8.5-fx+mz+sm-macosx.xpi'
var mozLinuxURL = 'https://addons.mozilla.org/en-US/firefox/downloads/file/25804/mozilla_xforms-0.8.5-fx+mz+sm-linux.xpi'
var mozVersion = '0.8.5' //not used yet

function checkXForms(){
    if (isFirefox()) {
        if (hasMozXForms()) { return; }
        
		switch (navigator.platform) {
			case "Win32": var url = mozWinURL;break;
			case "Linux": var url = mozLinuxURL;break;
			case "MacOSX": var url = mozMacURL;break;
			default: message('Firefox: Mozilla XForms not available for your browser platform');return;
		}
		
		xpi = {
			'Mozilla XForms 0.8 Release Extension': url
		};		
        message('Installing XForms add-on...');
        InstallTrigger.install(xpi);
    }
	else {
		message("PNEngine requires Firefox 2 for full support of XForms.")
	}
    /*else 
        if (isIE()) {
            var useFormsPlayer = 1;
            if (useFormsPlayer) {
                var classId = "CLSID:4D0ABA11-C5F0-4478-991A-375C4B648F58";
                var fpCab = "http://www.formsplayer.com/download/download/cab/formsPlayer.cab";
                document.write('<object classid="' + classId + '" height="0" id="FormsPlayer" width="0" codebase="' + fpCab + '" ><b>FormsPlayer has failed to load! Please check your installation.</b></object><?import namespace="xforms" implementation="#FormsPlayer"?>');
                message('IE: Enabling formsPlayer, may see additional messages if installation is needed.');
            }
            else {
                if (!hasMozzIE()) {
                    message('IE: MozzIE add-on is NOT installed');
                    document.write('<p>MozzIE is NOT installed</p>');
                    document.write('<p>You can download MozzIE from <a href="http://www.sourceforge.net/projects/mozzie">Here</a></p>');
                }
                else {
                    message('IE: MozzIE add-on is installed');
                }
            }
        }
        else 
            if (isOpera() || isSafari()) {
                message('Opera/Safari: Enabling FormFaces');
                var script = document.createElement('script');
                script.src = 'FormFaces/formfaces.js';
                script.type = 'text/javascript';
                var head = document.getElementsByTagName('head')[0];
                head.appendChild(script);
            }
            else 
                if (isXSmiles()) {
                    message('XSmiles: Builtin XForms support, no action taken.');
                }
                else {
                    message('Unsupported browser and XForms combination detected.  Only Mozilla, X-Smiles and Internet Explorer may be used.');
                }*/
}

function isFirefox(){
	return (navigator.appName == 'Netscape');
}
function isIE(){
    return (navigator.appName == 'Microsoft Internet Explorer');
}
function isOpera(){
    return (navigator.appName == 'Opera');
}
function isSafari(){
    return (navigator.appName == 'Safari');
}
function isXSmiles(){
    return (navigator.appName == 'X-Smiles');
}
function hasMozzIE(){
    return (navigator.userAgent.indexOf("Mozzie") > -1);
}
function hasMozXForms(){
    return (document.implementation.hasFeature("org.w3c.xforms.dom", "1.0"));
}

function message(msg){
    alert(msg);
}

checkXForms();
